<?php
/**
 * User: 魔十七
 * Date: 2020/11/11
 * Time: 8:30
 */
namespace Samecity\Model;

use Think\Model;

class CateringModel extends Model
{
    /**
     * 商铺是否正常
     * @param   $shop_id     商铺ID
     */
    public function getIsMerchant($shop_id)
    {
        $where['id'] = $shop_id;
        $data = M('catering')->where($where)->find();
        return $data;
    }

    /**
     * 店铺审核成功,生成相关信息
     */
    public function CateringAdd($array)
    {
        $phone   = $array['tel'];
        /* 查询当前账号是否存在 */
        $where['tel']   = $array['tel'];
        $exist = M('catering')->where($where)->find();

        $uid = $array['tel'];               /* 默认账号 */
        $password = $this->getPassWord();   /* 默认密码 */

        $type = $array['type']; /* 店铺类型 */

        if (!$exist){

            $resulet = array(
                'type'      => $type,
                'uid'       => $uid,
                'pwd'       => md5($password),
                'title'     => $array['title'],
                'province'  => $array['province'],
                'shi'       => $array['shi'],
                'county'    => $array['county'],
                'city'      => $array['city'],
                'xm'        => $array['xm'],
                'tel'       => $array['tel'],
                'gs_cer'    => $array['gs_cer'],
                'add_date'  => time(),
                'user_id'   => $array['uid'],
                'longitude' => $array['longitude'],
                'latitude'  => $array['latitude'],
            );

            $data = M('catering')->add($resulet);
            if ($data){
                $res['amount_number']    = $uid;
                $res['pwd']  = $password;
            }
        } else {
            $res['msg']  = '您已开通成功!';
            $res['amount_number']    = $uid;
            $res['pwd']  = $password;
        }
        $res['code']    = '1001';

        return $res;
    }

    /**
     * 生成密码
     */
    public function getPassWord()
    {
        //$randStr = str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890');
        //$rand = substr($randStr,0,6);
        $rand = 123456;
        return $rand;
    }
}